import { createRouter, createWebHistory } from 'vue-router';
import UserLayout from '@/components/layouts/UserLayout.vue';
import { interceptor } from './interceptor';
import { getRouteItem } from './utils';

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: [{
		path: '/user',
		name: 'UserLayout',
		component: UserLayout,
		redirect: '/user-login',
		children: [{
			component: () => import('@/views/common/login'),
			...getRouteItem('user-login', { label: '登录', useAnimation: false })
		}]
	}],
	scrollBehavior(to, from, savedPosition) {
		return to.name === 'Detail' ? { top: 0 } : savedPosition;
	}
});
interceptor(router);
export default router;